package com.tanhua.server.controller;

import com.tanhua.model.vo.CommentVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 圈子控制层
 */
@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private CommentsService commentsService;


    /**
     * 圈子互动-评论列表分页查询
     *
     * @param page
     * @param pageSize
     * @param movementId
     * @return
     */
    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity findPageComments(@RequestParam(value = "page", defaultValue = "1") Long page, @RequestParam(value = "pagesize", defaultValue = "10") Long pageSize, String movementId) {
        PageResult<CommentVo> pageResult = commentsService.findPageComments(page, pageSize, movementId);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 发布评论
     * @return
     */
    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity addComment(@RequestBody Map<String,String> params) {
        String publishId = params.get("movementId");//动态id
        String content = params.get("comment");//评论内容
        commentsService.addComment(publishId,content);
        return ResponseEntity.ok(null);
    }



}
